#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=60;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL ans[maxn][maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
     memset(ans,0,sizeof(ans));
     LL n,m,a,b;cin>>n>>m>>a>>b;
     if(n*a!=m*b){
        cout<<"NO"<<"\n";continue;
     }
     cout<<"YES"<<"\n";
     LL last=1;
     for(LL i=1;i<=n;i++){
        LL cnt=0;
        while(cnt<a){
           ans[i][last]=1;
           cnt++;
           last=(last%m)+1;
        }
     }
     for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++) cout<<ans[i][j];
        cout<<"\n";
     }
   }
   return 0;
}
